package sfin.swt.composite;

import java.util.ResourceBundle;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

import sfin.controller.ContaController;
import sfin.controller.LancamentoController;
import sfin.swt.data.ResumoData;

public class ResumoFinanceiroComposite extends Composite{

	
	private LancamentoController lancamentoController;
	private ContaController contaController;
	
	private Table resumeTable;
	private ResourceBundle bundle;
	private Table creditCardTable;
	private Table finalResumeTable;
	
	public ResumoFinanceiroComposite(Composite parent, int style, ResourceBundle bundle, LancamentoController lancamentoController, ContaController contaController) {
		super(parent, style);
		this.bundle = bundle;
		this.lancamentoController = lancamentoController;
		this.contaController = contaController;
		createResumeTable();
		createCreditCardTable();
		createFinalResumeTable();
		fillData();
	}

	private void createResumeTable(){
		
		setLayout(new GridLayout(2,true));
		
		Label label = new Label(this, SWT.NONE);
		label.setText(bundle.getString("string.general.label.account"));
		
		GridData gridData = new GridData();
		gridData.horizontalAlignment = GridData.END;
		label.setLayoutData(gridData);
		
		label = new Label(this, SWT.NONE);
		label.setText(contaController.getApplicationAccountName());
		
		gridData = new GridData();
		gridData.horizontalAlignment = GridData.BEGINNING;
		label.setLayoutData(gridData);
		
		//Tabela Resumo
		resumeTable = new Table(this, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
		resumeTable.setLinesVisible(true);
		resumeTable.setHeaderVisible(true);
		
		int width = 150;
		
		TableColumn column = new TableColumn(resumeTable, SWT.NONE);
		column.setWidth(width);
		column.setText(bundle.getString("resumo.table.header.grupo"));
		
		column = new TableColumn(resumeTable, SWT.NONE);
		column.setWidth(width);
		column.setText(bundle.getString("resumo.table.header.total"));
		
		column = new TableColumn(resumeTable, SWT.NONE);
		column.setWidth(width);
		column.setText(bundle.getString("resumo.table.header.percRec"));
		
		column = new TableColumn(resumeTable, SWT.NONE);
		column.setWidth(width);
		column.setText(bundle.getString("resumo.table.header.percDes"));
		
		
		gridData = new GridData(GridData.FILL_HORIZONTAL);
		gridData.horizontalSpan = 2;
		resumeTable.setLayoutData(gridData);
		
		
		
	}
	
	
	private void createCreditCardTable(){
		
				Label label = new Label(this,SWT.NONE);
				int width = 150;
				
				label.setText(bundle.getString("lancamento.enum.paymethod.credcard"));
				GridData gridData = new GridData();
				gridData.horizontalSpan = 2;
				gridData.horizontalAlignment = GridData.BEGINNING;
				label.setLayoutData(gridData);
				
				
				creditCardTable = new Table(this, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
				creditCardTable.setLinesVisible(true);
				//creditCardTable.setHeaderVisible(true);
				
				TableColumn column = new TableColumn(creditCardTable, SWT.NONE);
				column.setWidth(width);
				column.setText(bundle.getString("resumo.table.header.grupo"));
				
				column = new TableColumn(creditCardTable, SWT.NONE);
				column.setWidth(width);
				column.setText(bundle.getString("resumo.table.header.total"));
				
				column = new TableColumn(creditCardTable, SWT.NONE);
				column.setWidth(width);
				column.setText(bundle.getString("resumo.table.header.percRec"));
				
				column = new TableColumn(creditCardTable, SWT.NONE);
				column.setWidth(width);
				column.setText(bundle.getString("resumo.table.header.percDes"));
				
				
				gridData = new GridData(GridData.FILL_HORIZONTAL);
				gridData.horizontalSpan = 2;
				creditCardTable.setLayoutData(gridData);
	
	}
	
	private void createFinalResumeTable(){
		
				Label label = new Label(this,SWT.NONE);
				label.setText(bundle.getString("resume.table.final.label"));
				
				int width = 150;
				
				GridData gridData = new GridData();
				gridData.horizontalSpan = 2;
				gridData.horizontalAlignment = GridData.BEGINNING;
				label.setLayoutData(gridData);
				
				finalResumeTable = new Table(this, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
				
				TableColumn column = new TableColumn(finalResumeTable, SWT.NONE);
				column.setWidth(width);
				
				column = new TableColumn(finalResumeTable, SWT.NONE);
				column.setWidth(width);
				
				gridData = new GridData(GridData.FILL_HORIZONTAL);
				gridData.horizontalSpan = 2;
				finalResumeTable.setLayoutData(gridData);
				
	}
	
	

	private void fillData() {

		ResumoData resumoData = lancamentoController.getResumoData();
		
		String[] data = new String[]{bundle.getString("grupo.lancamento.receita.name"),resumoData.receita, "",""};
		TableItem tableItem = new TableItem(resumeTable, SWT.NONE);
		tableItem.setText(data);
		
		data = new String[]{bundle.getString("grupo.lancamento.investimento.name"),resumoData.investimento, resumoData.investimentoPercRec,resumoData.investimentoPercDes};
		tableItem = new TableItem(resumeTable, SWT.NONE);
		tableItem.setText(data);
		
		data = new String[]{bundle.getString("grupo.lancamento.despesa-fixa.name"),resumoData.despesaFixa, resumoData.despesaFixaPercRec,resumoData.despesaFixaPercDes};
		tableItem = new TableItem(resumeTable, SWT.NONE);
		tableItem.setText(data);
		
		data = new String[]{bundle.getString("grupo.lancamento.despesa-variavel.name"),resumoData.despesaVariavel, resumoData.despesaVariavelPercRec,resumoData.despesaVariavelPercDes};
		tableItem = new TableItem(resumeTable, SWT.NONE);
		tableItem.setText(data);

		data = new String[]{bundle.getString("grupo.lancamento.despesa-adicional.name"),resumoData.despesaAdicional, resumoData.despesaAdicionalPercRec,resumoData.despesaAdicionalPercDes};
		tableItem = new TableItem(resumeTable, SWT.NONE);
		tableItem.setText(data);
		
		data = new String[]{bundle.getString("grupo.lancamento.despesa-extra.name"),resumoData.despesaExtra, resumoData.despesaExtraPercRec,resumoData.despesaExtraPercDes};
		tableItem = new TableItem(resumeTable, SWT.NONE);
		tableItem.setText(data);
		
		data = new String[]{bundle.getString("string.general.expense.total"),resumoData.despesaTotal, resumoData.despesaTotalPercRec,resumoData.despesaTotalPercDes};
		tableItem = new TableItem(resumeTable, SWT.NONE);
		tableItem.setText(data);

		data = new String[]{bundle.getString("string.general.resume.saldo-entrada"),resumoData.saldoEntrada, "",""};
		tableItem = new TableItem(resumeTable, SWT.NONE);
		tableItem.setText(data);

		data = new String[]{bundle.getString("string.general.resume.saldo-saida"),resumoData.saldoSaida, "",""};
		tableItem = new TableItem(resumeTable, SWT.NONE);
		tableItem.setText(data);
		
		data = new String[]{bundle.getString("string.general.resume.saldo"),resumoData.saldo, "",""};
		tableItem = new TableItem(resumeTable, SWT.NONE);
		tableItem.setText(data);
		
		
		data = new String[]{bundle.getString("string.general.total.credit-card"),resumoData.cartaoCredito, resumoData.cartaoCreditoPercRec,resumoData.cartaoCreditoPercDes};
		tableItem = new TableItem(creditCardTable, SWT.NONE);
		tableItem.setText(data);
		
		
		data = new String[]{bundle.getString("resume.table.final.pg"),resumoData.pago};
		tableItem = new TableItem(finalResumeTable, SWT.NONE);
		tableItem.setText(data);
		
		data = new String[]{bundle.getString("resume.table.final.npg"),resumoData.naoPago};
		tableItem = new TableItem(finalResumeTable, SWT.NONE);
		tableItem.setText(data);

		data = new String[]{bundle.getString("resume.table.final.cc-sal"),resumoData.saldoConta};
		tableItem = new TableItem(finalResumeTable, SWT.NONE);
		tableItem.setText(data);
		
		
	}
	
	
}
